package com.ruoyi.web.controller.project;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.Assets;
import com.ruoyi.project.service.IAssetsService;
import com.ruoyi.web.core.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;

/**
 * 资产管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-01
 */
@Controller
@RequestMapping("/project/assets")
public class AssetsController extends BaseController
{
    private String prefix = "project/assets";

	@Autowired
	private IAssetsService assetsService;

	@RequiresPermissions("project:assets:view")
	@GetMapping()
	public String assets()
	{
	    return prefix + "/assets";
	}
	
	/**
	 * 查询资产管理列表
	 */
	@RequiresPermissions("project:assets:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Assets assets)
	{
		startPage();
        List<Assets> list = assetsService.selectAssetsList(assets);
		return getDataTable(list);
	}
	
	/**
	 * 新增资产管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存资产管理
	 */
	@RequiresPermissions("project:assets:add")
	@Log(title = "资产管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Assets assets)
	{		
		return toAjax(assetsService.insertAssets(assets));
	}

	/**
	 * 修改资产管理
	 */
	@GetMapping("/edit/{assetsId}")
	public String edit(@PathVariable("assetsId") Long assetsId, ModelMap mmap)
	{
		Assets assets = assetsService.selectAssetsById(assetsId);
		mmap.put("assets", assets);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存资产管理
	 */
	@RequiresPermissions("project:assets:edit")
	@Log(title = "资产管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Assets assets)
	{		
		return toAjax(assetsService.updateAssets(assets));
	}
	
	/**
	 * 删除资产管理
	 */
	@RequiresPermissions("project:assets:remove")
	@Log(title = "资产管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(assetsService.deleteAssetsByIds(ids));
	}
	
}
